home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / sbin_-_Static_Binary_Files / NETCONFI.{2V < prev    next >
Text File  |  1999-09-17  |  15KB  |  504 lines

  1. #!/bin/sh
  2. # This checks IP address syntax.
  3. # usage: syntax_check ADDRESS #-OF-EXPECTED-SEGMENTS (up to 4)
  4. # example: syntax_check 123.22.43.1 4
  5. # returns: 0=found correct  1=too many fields  2=non numeric field found
  6. TMP=/var/log/setup/tmp
  7. if [ ! -d $TMP ]; then
  8.  mkdir -p $TMP
  9.  chmod 700 $TMP
  10. fi
  11. syntax_check_color() {
  12.   RET_CODE=0 
  13.   SCRATCH=$1
  14.   SCRATCH=`echo $SCRATCH | tr "." "/"`
  15.   INDEX=$2
  16.   while [ ! "$INDEX" = "0" ]; do
  17.     # OK, so I'm a LISP-head :^)
  18.     FIELD=`basename $SCRATCH`
  19.     SCRATCH=`dirname $SCRATCH`
  20.     if expr $FIELD + 1 1> /dev/null 2> /dev/null; then
  21.       GOOD=y
  22.     else
  23.       RET_CODE=2; # non-numeric field
  24.     fi
  25.     INDEX=`expr $INDEX - 1`
  26.   done
  27.   if [ ! "$SCRATCH" = "." ]; then
  28.     RET_CODE=1; # too many arguments
  29.   fi
  30.   if [ "$3" = "WARN" -a ! "$RET_CODE" = "0" ]; then
  31.     cat << EOF > $TMP/tempmsg
  32.  
  33. The address you have entered seems to be non-standard. We were expecting
  34. $2 groups of numbers seperated by dots, like: 127.0.0.1
  35. Are you absolutely sure you want to use the address $1?
  36.  
  37. EOF
  38.     dialog --title "WARNING" --yesno "`cat $TMP/tempmsg`" 9 72
  39.     if [ $? = 0 ]; then
  40.       RET_CODE = 0;
  41.     fi
  42.     rm -r $TMP/tempmsg
  43.   else
  44.     if [ "$3" = "ECHO" ]; then
  45.       echo $RET_CODE;
  46.     fi
  47.   fi
  48.   return $RET_CODE;
  49. }
  50.  
  51. if [ ! -d lost+found -a ! -d vmlinuz -a ! -d proc ]; then # cheap, but it works :^)
  52.  cd /
  53. fi;
  54.  
  55. # IMPORTANT!!! NO LEADING '/' in the paths below, or this script will not
  56. # function from the bootdisk.
  57. IFCONFIG=sbin/ifconfig            # Where ifconfig program is.
  58. ROUTE=sbin/route            # Where route program is.
  59. RC=etc/rc.d/rc.inet1            # Where rc.inet1 file is.
  60. RESOLV=etc/resolv.conf            # Where resolv.conf file is.
  61. HOSTS=etc/hosts                 # Where hosts file is.
  62. ETCNETWORKS=etc/networks        # Where networks file is.
  63. SMAIL=var/lib/smail/config        # Smail configuration file
  64. ELMRC=var/lib/elm/elm.rc        # ELM rc file
  65. #
  66. # defaults:
  67. NETWORK=127.0.0.0
  68. IPADDR=127.0.0.1
  69. NETMASK=255.255.255.0
  70. #
  71. ############################################################################
  72. #             Question and answer.
  73. ############################################################################
  74. #
  75. cat << EOF > $TMP/tempmsg
  76.  
  77. Now we will attempt to configure your mail and TCP/IP. This 
  78. process probably won't work on all possible network 
  79. configurations, but should give you a good start. You will be
  80. able to reconfigure your system at any time by typing:
  81.   
  82.   netconfig
  83.  
  84. EOF
  85. dialog --title "NETWORK CONFIGURATION" --msgbox "`cat $TMP/tempmsg`" 12 70
  86. while [ 0 ]; do
  87. cat << EOF > $TMP/tempmsg
  88. First, we'll need the name you'd like to give your host. Only
  89. the base hostname is needed right now. (not the domain)
  90.  
  91. Enter hostname:
  92. EOF
  93.  dialog --title "ENTER HOSTNAME" --inputbox "`cat $TMP/tempmsg`" 11 70 \
  94.  $HOSTNM 2> $TMP/SeThost
  95.  if [ $? = 1 -o $? = 255 ]; then
  96.   rm -f $TMP/SeThost $TMP/tempmsg
  97.   exit
  98.  fi
  99.  HOSTNM="`cat $TMP/SeThost`"
  100.  rm -f $TMP/SeThost $TMP/tempmsg
  101.  if [ ! "$HOSTNM" = "" ]; then
  102.   break;
  103.  fi
  104. done
  105.  
  106. while [ 0 ]; do
  107. cat << EOF > $TMP/tempmsg
  108. Now, we need the domain name. Do not supply a leading '.'
  109.  
  110. Enter domain name for $HOSTNM: 
  111. EOF
  112.  dialog --title "ENTER DOMAINNAME" --inputbox "`cat $TMP/tempmsg`" \
  113. 10 70 $DOMAIN 2> $TMP/SeTdom
  114.  if [ $? = 1 -o $? = 255 ]; then
  115.   rm -f $TMP/SeTdom $TMP/tempmsg
  116.   exit
  117.  fi
  118.  DOMAIN="`cat $TMP/SeTdom`"
  119.  rm -f $TMP/SeTdom $TMP/tempmsg
  120.  if [ ! "$DOMAIN" = "" ]; then
  121.   break;
  122.  fi
  123. done
  124.  
  125. echo $HOSTNM.$DOMAIN > etc/HOSTNAME
  126.  
  127. cat << EOF > $TMP/tempmsg
  128. If you only plan to use TCP/IP through loopback, then your
  129. IP address will be 127.0.0.1 and we can skip a lot of the 
  130. following questions.
  131.  
  132. Do you plan to ONLY use loopback? 
  133. EOF
  134. dialog --title "LOOPBACK ONLY?" --yesno "`cat $TMP/tempmsg`" 9 70
  135. if [ $? = 0 ]; then
  136.  LOOPBACK="y"
  137. else
  138.  LOOPBACK="n"
  139. fi
  140.  
  141. if [ -r bin/telnet -a "$LOOPBACK" = "n" ]; then
  142.  
  143.  while [ 0 ]; do
  144.   if [ -r $TMP/SeTIP ]; then
  145.    IPADDR=`cat $TMP/SeTIP`
  146.   fi
  147.   cat << EOF > $TMP/tempmsg
  148. Enter your IP address for the local machine. Example: 
  149. 111.112.113.114
  150. Enter IP address for $HOSTNM (aaa.bbb.ccc.ddd): 
  151. EOF
  152.   dialog --title "ENTER LOCAL IP ADDRESS" --inputbox "`cat $TMP/tempmsg`" \
  153. 10 68 $IPADDR 2> $TMP/SeTlip
  154.   if [ $? = 1 -o $? = 255 ]; then
  155.    rm -f $TMP/SeTlip $TMP/tempmsg
  156.    exit
  157.   fi
  158.   IPADDR="`cat $TMP/SeTlip`"
  159.   rm -f $TMP/SeTlip $TMP/tempmsg
  160.   if [ "$IPADDR" = "" ]; then
  161.    continue;
  162.   fi
  163.   syntax_check_color $IPADDR 4 WARN
  164.   if [ $? = 0 ]; then
  165.    echo $IPADDR > $TMP/SeTIP
  166.    break;
  167.   fi
  168.  done
  169.  
  170.  while [ 0 ]; do
  171.   if [ -r $TMP/SeTnetmask ]; then
  172.    NETMASK=`cat $TMP/SeTnetmask`
  173.   fi
  174.   cat << EOF > $TMP/tempmsg
  175. Enter your netmask. This will generally look something
  176. like this: 255.255.255.0
  177. Enter netmask (aaa.bbb.ccc.ddd):
  178. EOF
  179.   dialog --title "ENTER NETMASK" --inputbox "`cat $TMP/tempmsg`" \
  180. 10 65 $NETMASK 2> $TMP/SeTnmask
  181.   if [ $? = 1 -o $? = 255 ]; then
  182.    rm -f $TMP/SeTnmask $TMP/tempmsg
  183.    exit
  184.   fi
  185.   NETMASK="`cat $TMP/SeTnmask`"
  186.   rm -f $TMP/SeTnmask $TMP/tempmsg
  187.   if [ "$NETMASK" = "" ]; then
  188.    continue;
  189.   fi
  190.   syntax_check_color $NETMASK 4 WARN
  191.   if [ $? = 0 ]; then
  192.    echo $NETMASK > $TMP/SeTnetmask
  193.    break;
  194.   fi
  195.  done
  196.  
  197. # Set broadcast/network addresses automatially:
  198.  
  199.  BROADCAST=`ipmask $NETMASK $IPADDR | cut -f 1 -d ' '`
  200.  NETWORK=`ipmask $NETMASK $IPADDR | cut -f 2 -d ' '`
  201.  
  202.  while [ 0 ]; do
  203.   if [ -r $TMP/SeTgateway ]; then
  204.    GATEWAY=`cat $TMP/SeTgateway`
  205.   fi
  206.   cat << EOF > $TMP/tempmsg
  207. Enter your gateway address, such as 111.112.113.1
  208.  
  209. If you don't have a gateway on your network, just hit
  210. ENTER without entering a gateway IP address.
  211.  
  212. Enter gateway address (aaa.bbb.ccc.ddd):
  213. EOF
  214.   dialog --title "ENTER GATEWAY ADDRESS" --inputbox "`cat $TMP/tempmsg`" \
  215.   13 65 $GATEWAY 2> $TMP/SeTgate
  216.   if [ $? = 1 -o $? = 255 ]; then
  217.    rm -f $TMP/SeTgate $TMP/tempmsg
  218.    exit
  219.   fi
  220.   GATEWAY="`cat $TMP/SeTgate`"
  221.   rm -f $TMP/SeTgate $TMP/tempmsg
  222.   if [ "$GATEWAY" = "" ]; then
  223.     break;
  224.   fi
  225.   syntax_check_color $GATEWAY 4 WARN
  226.   if [ $? = 0 ]; then
  227.     echo $GATEWAY > $TMP/SeTgateway
  228.     break;
  229.   fi
  230.  done
  231.  
  232. else
  233.  if [ ! -r bin/telnet ]; then
  234.   cat << EOF > $TMP/tempmsg
  235.  
  236. You do not seem to have TCP/IP installed, so all I can really set
  237. up for you is your hostname/domainname. This won't mean much 
  238. since you're not on the network, but it will let you have the 
  239. hostname you prefer shown at the login prompt.
  240.  
  241. EOF
  242.   dialog --title "SKIPPING MOST OF THE CONFIG PROCESS" \
  243. --infobox "`cat $TMP/tempmsg`" 10 70
  244.  fi
  245. fi
  246.  
  247. #
  248. ############################################################################
  249. #              The rc.inet1 file.
  250. ############################################################################
  251. #
  252. # echo "Creating /$RC..."
  253. if [ "$LOOPBACK" = "n" ]; then # we are using an ethernet card
  254.  /bin/cat <<EOF >$RC
  255. #! /bin/sh
  256. #
  257. # rc.inet1    This shell script boots up the base INET system.
  258. #
  259. # Version:    @(#)/etc/rc.d/rc.inet1    1.01    05/27/93
  260. #
  261.  
  262. HOSTNAME=\`cat /etc/HOSTNAME\`
  263.  
  264. # Attach the loopback device.
  265. /$IFCONFIG lo 127.0.0.1
  266. /$ROUTE add -net 127.0.0.0 netmask 255.0.0.0 lo
  267.  
  268. # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
  269. # eth0 interface. If you're only using loopback or SLIP, don't include the
  270. # rest of the lines in this file.
  271.  
  272. # Edit for your setup.
  273. IPADDR="$IPADDR"    # REPLACE with YOUR IP address!
  274. NETMASK="$NETMASK"    # REPLACE with YOUR netmask!
  275. NETWORK="$NETWORK"    # REPLACE with YOUR network address!
  276. BROADCAST="$BROADCAST"    # REPLACE with YOUR broadcast address, if you
  277.             # have one. If not, leave blank and edit below.
  278. GATEWAY="$GATEWAY"    # REPLACE with YOUR gateway address!
  279.  
  280. # Uncomment the line below to configure your ethernet card.
  281. /$IFCONFIG eth0 \${IPADDR} broadcast \${BROADCAST} netmask \${NETMASK}
  282.  
  283. # If the line above is uncommented, the code below can also be uncommented.
  284. # It sees if the ethernet was properly initialized, and gives the admin some
  285. # hints about what to do if it wasn't.
  286. if [ ! \$? = 0 ]; then
  287.   cat << END
  288. Your ethernet card was not initialized properly.  Here are some reasons why this
  289. may have happened, and the solutions:
  290. 1. Your kernel does not contain support for your card.  Including all the 
  291.    network drivers in a Linux kernel can make it too large to even boot, and
  292.    sometimes including extra drivers can cause system hangs.  To support your
  293.    ethernet, either edit /etc/rc.d/rc.modules to load the support at boottime,
  294.    or compile and install a kernel that contains support.
  295. 2. You don't have an ethernet card, in which case you should comment out this
  296.    section of /etc/rc.d/rc.inet1.  (Unless you don't mind seeing this error...)
  297. END
  298. fi
  299.  
  300. # Older kernel versions need this to set up the eth0 routing table:
  301. KVERSION=`uname -r | cut -f 1,2 -d .`
  302. if [ "\$KVERSION" = "1.0" -o "\$KVERSION" = "1.1" \\
  303.  -o "\$KVERSION" = "1.2" -o "\$KVERSION" = "2.0" -o "\$KVERSION" = "" ]; then
  304.  /$ROUTE add -net \${NETWORK} netmask \${NETMASK} eth0
  305. fi
  306.  
  307. # Uncomment this to set up your gateway route:
  308. if [ ! "\$GATEWAY" = "" ]; then
  309.  /$ROUTE add default gw \${GATEWAY} netmask 0.0.0.0 metric 1
  310. fi
  311.  
  312. # End of rc.inet1
  313. EOF
  314.  chmod 755 $RC
  315. else # we are only using loopback
  316.  /bin/cat <<EOF >$RC
  317. #! /bin/sh
  318. #
  319. # rc.inet1    This shell script boots up the base INET system.
  320. #
  321. # Version:    @(#)/etc/rc.d/rc.inet1    1.01    05/27/93
  322. #
  323.  
  324. HOSTNAME=\`cat /etc/HOSTNAME\`
  325.  
  326. # Attach the loopback device.
  327. /$IFCONFIG lo 127.0.0.1
  328. /$ROUTE add -net 127.0.0.0 netmask 255.0.0.0 lo
  329.  
  330. # IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the 
  331. # eth0 interface. If you're only using loopback or SLIP, don't include the
  332. # rest of the lines in this file.
  333.  
  334. # Edit for your setup.
  335. #IPADDR="$IPADDR"    # REPLACE with YOUR IP address!
  336. #NETMASK="$NETMASK"    # REPLACE with YOUR netmask!
  337. #NETWORK="$NETWORK"    # REPLACE with YOUR network address!
  338. #BROADCAST="$BROADCAST"    # REPLACE with YOUR broadcast address, if you
  339.             # have one. If not, leave blank and edit below.
  340. #GATEWAY="$GATEWAY"    # REPLACE with YOUR gateway address!
  341.  
  342. # Uncomment the line below to initialize the ethernet device.
  343. #/$IFCONFIG eth0 \${IPADDR} broadcast \${BROADCAST} netmask \${NETMASK}
  344.  
  345. # Uncomment these to set up your IP routing table.
  346. #/$ROUTE add -net \${NETWORK} netmask \${NETMASK} eth0
  347. #/$ROUTE add default gw \${GATEWAY} netmask 0.0.0.0 metric 1
  348.  
  349. # End of rc.inet1
  350. EOF
  351.  chmod 755 $RC
  352. fi # write out the script
  353. #
  354. ############################################################################
  355. #              The networks file.
  356. ############################################################################
  357. #
  358. #echo "Creating /$ETCNETWORKS..."
  359. /bin/cat <<EOF >$ETCNETWORKS
  360. #
  361. # networks    This file describes a number of netname-to-address
  362. #        mappings for the TCP/IP subsystem.  It is mostly
  363. #        used at boot time, when no name servers are running.
  364. #
  365.  
  366. loopback    127.0.0.0
  367. localnet    $NETWORK
  368.  
  369. # End of networks.
  370. EOF
  371. chmod 644 $ETCNETWORKS
  372. #
  373. ############################################################################
  374. #               The hosts file.
  375. ############################################################################
  376. #
  377. #echo "Creating /$HOSTS..."
  378. /bin/cat <<EOF >$HOSTS
  379. #
  380. # hosts        This file describes a number of hostname-to-address
  381. #        mappings for the TCP/IP subsystem.  It is mostly
  382. #        used at boot time, when no name servers are running.
  383. #        On small systems, this file can be used instead of a
  384. #        "named" name server.  Just add the names, addresses
  385. #        and any aliases to this file...
  386. #
  387. # By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
  388. # should NEVER be named with the name of the machine.  It causes problems
  389. # for some (stupid) programs, irc and reputedly talk. :^)
  390. #
  391.  
  392. # For loopbacking.
  393. 127.0.0.1    localhost
  394. $IPADDR         $HOSTNM.$DOMAIN $HOSTNM
  395.  
  396. # End of hosts.
  397.  
  398. EOF
  399. chmod 644 $HOSTS
  400. #
  401. ##########################################################################
  402. # The Smail 3.1.28 configuration file 
  403. ##########################################################################
  404. #
  405. #mkdir -p `dirname $SMAIL`
  406. ##echo "Creating /$SMAIL..."
  407. #/bin/cat <<EOF >$SMAIL
  408. ##
  409. ##    smail configuration for $HOSTNM
  410. ## (see smail(5) man page for details and other options)
  411. ##
  412. #-smtp_debug
  413. #hostname=$HOSTNM.$DOMAIN
  414. #visible_domain=$DOMAIN
  415. #more_hostnames=$HOSTNM.$DOMAIN
  416. #postmaster=postmaster
  417. #smtp_accept_max=10
  418. #EOF
  419. #echo 'smtp_banner="$primary_name Linux Smail$version #$compile_num ready at $date"' >> $SMAIL
  420. #echo 'received_field="Received: \' >> $SMAIL
  421. #echo '    ${if def:sender_host \' >> $SMAIL
  422. #echo '        {from $sender_host by $primary_name \' >> $SMAIL
  423. #echo '        ${if def:sender_proto: with $sender_proto}\' >> $SMAIL
  424. #echo '        \n\t(Linux Smail$version #$compile_num) }\' >> $SMAIL
  425. #echo '    else{by $primary_name ${if def:sender_proto:with $sender_proto }\' >> $SMAIL
  426. #echo '        (Linux Smail$version #$compile_num)\n\t}}\' >> $SMAIL
  427. #echo '    id $message_id; $spool_date"' >> $SMAIL
  428. #chmod 644 $SMAIL
  429. ##
  430. ############################################################################
  431. # The ELM rc file
  432. ############################################################################
  433. #
  434. mkdir -p `dirname $ELMRC`
  435. #echo "Creating /$ELMRC..."
  436. /bin/cat <<EOF >$ELMRC
  437. #------------------------ global elm.rc file ------------------
  438. #
  439. # this expects any global aliases in /usr/lib/aliases.text
  440. #
  441. # you probably also want to set the visible_name parameter in 
  442. # /usr/lib/smail/config if you use smail3.1.28
  443. #
  444. # this is the unqualified hostname
  445. #
  446. hostname = $HOSTNM
  447. #
  448. # this is the local domain
  449. #
  450. hostdomain = .$DOMAIN
  451. #
  452. # this is the fully qualified hostname
  453. #
  454. hostfullname = $HOSTNM.$DOMAIN
  455. EOF
  456. chmod 644 $ELMRC
  457. #
  458. ############################################################################
  459. #            The resolv.conf file.
  460. ############################################################################
  461. #
  462. if [ "$LOOPBACK" = "n" ]; then
  463.  dialog --title "USE A NAMESERVER?" --yesno "Will you be accessing a \
  464. nameserver?" 5 50 
  465.  if [ $? = 0 ]; then
  466.   while [ "$NAMESERVER" = "" ]; do
  467.    cat << EOF > $TMP/tempmsg
  468. Here is your current IP address, full hostname, and base hostname:
  469. $IPADDR       $HOSTNM.$DOMAIN    $HOSTNM
  470.  
  471. Please give the IP address of the name server to use. 
  472. You can add more Domain Name Servers by editing /$RESOLV.
  473.  
  474. Name Server for domain $DOMAIN (aaa.bbb.ccc.ddd): 
  475. EOF
  476.    dialog --title "SELECT NAMESERVER" --inputbox \
  477. "`cat $TMP/tempmsg`" 14 72 2> $TMP/SeTns
  478.    if [ $? = 1 -o $? = 255 ]; then
  479.     rm -f $TMP/tempmsg $TMP/SeTns 
  480.    fi
  481.    NAMESERVER="`cat $TMP/SeTns`"
  482.    rm -f $TMP/tempmsg $TMP/SeTns 
  483.   done
  484.   echo "search $DOMAIN" >$RESOLV
  485.   echo "nameserver $NAMESERVER" >>$RESOLV
  486.  else
  487.   echo "search $DOMAIN" >$RESOLV
  488.  fi
  489. fi
  490. if [ "$LOOPBACK" = "n" ]; then chmod 644 $RESOLV ;fi
  491. #
  492. ############################################################################
  493. #             Change permissions and exit.
  494. ############################################################################
  495. #
  496. dialog --title "NETWORK SETUP COMPLETE" --msgbox "Your networking \
  497. software has now been configured. IMPORTANT: Remember that most precompiled \
  498. Linux kernels do not have network drivers compiled into them, since \
  499. compiling them all in results in kernels that are too large to boot. \
  500. If you need a driver that is not present in your kernel, either \
  501. recompile the kernel to include the necessary driver or load the \
  502. driver as a module by editing /etc/rc.d/rc.modules." 11 64
  503. rm -f $TMP/tempmsg
  504.